<template>
  <div>
    <div class="radioBar">
      <el-radio-group v-model="type" @change="showChart">
        <el-radio-button label="上周销量统计"></el-radio-button>
        <el-radio-button label="本周销量统计"></el-radio-button>
        <el-radio-button label="下周销量预期"></el-radio-button>
      </el-radio-group>
    </div>
    <div class="total" id="myChart" ref="myChart"></div>
  </div>
</template>

<script>
import echarts from "echarts";
import axios from "axios";
export default {
  data() {
    return {
      type: "上周销量统计",
    };
  },
  mounted() {
    // this.$nextTick(() => {
    //     this.showChart();
    // });
    this.showChart();
  },
  methods: {
    showChart() {
      // 销毁之前的实例
      echarts.dispose(this.$refs.myChart);
      // 重新创建新的实例
      let myChart = echarts.init(this.$refs.myChart);
      if (this.type == "上周销量统计") {
        myChart.setOption(this.supplierFoodsOptionsPre, true);
      } else if (this.type == "本周销量统计") {
         myChart.setOption(this.supplierFoodsOptionsCur, true);
      } else {
         myChart.setOption(this.supplierFoodsOptionsNext, true);
      }
    }
  },
  computed: {
    supplierFoodsOptionsPre() {
      return {
        title: {
          text: "上周销量统计"
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            // 坐标轴指示器，坐标轴触发有效
            type: "shadow" // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        legend: {
          data: [
            "主粮",
            "洗浴",
            "日用品",
            "零食",
            "保健品",
            "医疗",
            "清洁洗护",
            "玩具",
          ]
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true
        },
        xAxis: [
          {
            type: "category",
            data: ["周一", "周二", "周三", "周四", "周五", "周六", "周日"]
          }
        ],
        yAxis: [
          {
            type: "value"
          }
        ],
        series: [
          {
            name: "保健品",
            type: "bar",
            data: [320, 332, 301, 334, 390, 330, 320]
          },
          {
            name: "洗浴",
            type: "bar",
            stack: "广告",
            data: [120, 132, 101, 134, 90, 230, 210]
          },
          {
            name: "日用品",
            type: "bar",
            stack: "广告",
            data: [220, 182, 191, 234, 290, 330, 310]
          },
          {
            name: "零食",
            type: "bar",
            stack: "广告",
            data: [150, 232, 201, 154, 190, 330, 410]
          },
          {
            name: "主粮",
            type: "bar",
            data: [1862, 1018, 964, 1800, 1679, 1600, 1570],
            markLine: {
              lineStyle: {
                type: "dashed"
              },
              data: [[{ type: "min" }, { type: "max" }]]
            }
          },
          {
            name: "医疗",
            type: "bar",
            barWidth: 5,
            data: [620, 732, 701, 734, 1090, 1130, 1120]
          },
          {
            name: "清洁洗护",
            type: "bar",
            data: [120, 132, 101, 134, 290, 230, 220]
          },
          {
            name: "玩具",
            type: "bar",
            data: [60, 72, 71, 74, 190, 130, 110]
          }
        ]
      };
    },
    supplierFoodsOptionsCur() {
      return {
        title: {
          text: "本周周销量统计"
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            // 坐标轴指示器，坐标轴触发有效
            type: "shadow" // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        legend: {
          data: [
            "主粮",
            "洗浴",
            "日用品",
            "零食",
            "保健品",
            "医疗",
            "清洁洗护",
            "玩具",
          ]
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true
        },
        xAxis: [
          {
            type: "category",
            data: ["周一", "周二", "周三", "周四", "周五", "周六", "周日"]
          }
        ],
        yAxis: [
          {
            type: "value"
          }
        ],
        series: [
          {
            name: "保健品",
            type: "bar",
            data: [320, 200, 301,100, 390, 330,500]
          },
          {
            name: "洗浴",
            type: "bar",
            stack: "广告",
            data: [20, 132, 101, 134, 90, 50, 210]
          },
          {
            name: "日用品",
            type: "bar",
            stack: "广告",
            data: [220, 182, 191, 234, 290, 330, 310]
          },
          {
            name: "零食",
            type: "bar",
            stack: "广告",
            data: [150, 232, 478, 154, 190, 330, 410]
          },
          {
            name: "主粮",
            type: "bar",
            data: [862, 1018, 964, 1026, 1300, 1600, 1570],
            markLine: {
              lineStyle: {
                type: "dashed"
              },
              data: [[{ type: "min" }, { type: "max" }]]
            }
          },
          {
            name: "医疗",
            type: "bar",
            barWidth: 5,
            data: [200, 732, 701, 734,300, 1130, 1120]
          },
          {
            name: "清洁洗护",
            type: "bar",
            data: [120, 132, 101, 134, 290, 230, 220]
          },
          {
            name: "玩具",
            type: "bar",
            data: [210, 72, 71, 74, 190, 130, 110]
          }
        ]
      };
    },
    supplierFoodsOptionsNext() {
      return {
        title: {
          text: "下周销量预期"
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            // 坐标轴指示器，坐标轴触发有效
            type: "shadow" // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        legend: {
          data: [
            "主粮",
            "洗浴",
            "日用品",
            "零食",
            "保健品",
            "医疗",
            "清洁洗护",
            "玩具",
          ]
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true
        },
        xAxis: [
          {
            type: "category",
            data: ["周一", "周二", "周三", "周四", "周五", "周六", "周日"]
          }
        ],
        yAxis: [
          {
            type: "value"
          }
        ],
        series: [
          {
            name: "保健品",
            type: "bar",
            data: [320, 123, 301, 334, 111, 330, 320]
          },
          {
            name: "洗浴",
            type: "bar",
            stack: "广告",
            data: [120, 132, 23, 134, 90, 230, 210]
          },
          {
            name: "日用品",
            type: "bar",
            stack: "广告",
            data: [444, 182, 33, 234, 290, 330, 310]
          },
          {
            name: "零食",
            type: "bar",
            stack: "广告",
            data: [150, 232, 201, 154, 190, 330, 410]
          },
          {
            name: "主粮",
            type: "bar",
            data: [1862, 1018, 964,1300, 800, 1600, 1570],
            markLine: {
              lineStyle: {
                type: "dashed"
              },
              data: [[{ type: "min" }, { type: "max" }]]
            }
          },
          {
            name: "医疗",
            type: "bar",
            barWidth: 5,
            
            data: [620, 732, 701, 734, 1090, 1130, 1120]
          },
          {
            name: "清洁洗护",
            type: "bar",
            
            data: [120, 34, 101, 134, 222, 230, 220]
          },
          {
            name: "玩具",
            type: "bar",
            
            data: [160, 172, 271, 74, 190, 130, 110]
          }
        ]
      };
    },
  }
};
</script>

<style scoped>
.total {
  width: 100%;
  height: 500px;
  margin-top: 50px;
}
.radioBar {
  width: 377px;
  height: 28px;
  margin: auto;
  margin-top: 20px;
}
</style>